package com.bustle.user.proxy;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

import com.bustle.commons.XmlParser;
import com.bustle.commons.data.dao.Dao;
import com.bustle.commons.data.dao.DaoProxy;
import com.bustle.commons.http.RestDtoDaoProxy;
import com.bustle.commons.http.TypeToXmlHttpConverter;
import com.bustle.user.dto.address.AddressDto;
import com.bustle.user.dto.address.AddressDtoDaoWebService.AddressDtoList;
import com.bustle.user.dto.address.AddressDtoMapper;

@Local
public interface AddressDtoDaoProxy extends Dao<Integer, AddressDto>
{
  @Stateless
  public class DefaultAddressDtoDaoProxy extends DaoProxy<Integer, AddressDto, Dao<Integer, AddressDto>> implements AddressDtoDaoProxy
  {
    @PostConstruct
    public void postBuild()
    {
      dao = new RestDtoDaoProxy<Integer, AddressDto>("localhost", 8080, "address", new XmlParser(), new TypeToXmlHttpConverter<>(AddressDto.class), AddressDto.class, dtoMapper)
        {
          @Override
          protected List<AddressDto> retrieveAllFrom(String aResult)
          {
            return parser.parse(AddressDtoList.class, aResult).getAddress();
          }
        };
    }

    @EJB
    protected AddressDtoMapper dtoMapper;
  }
}